#ifndef OBSERVER_PATTERN_H
#define OBSERVER_PATTERN_H

#include <vector>

using namespace std;

class Observer;

class Subject
{
public:
    ~Subject();

    int getState();
    void setState(int state);
    void attach(Observer* observer);
    void notifyAllObservers();

private:
    vector<Observer*> observers;
    int state;
};

class Observer
{
public:
    virtual ~Observer() {}
    virtual void update() = 0;

protected:
    Subject* subject;
};

class BinaryObserver : public Observer
{
public:
    BinaryObserver(Subject* subject);
    ~BinaryObserver();

    void update() override;
};

class OctalObserver : public Observer
{
public:
    OctalObserver(Subject* subject);
    ~OctalObserver();

    void update() override;
};

class HexaObserver : public Observer
{
public:
    HexaObserver(Subject* subject);
    ~HexaObserver();

    void update() override;
};

#endif // OBSERVER_PATTERN_H

/*
    Subject* subject = new Subject();

    new HexaObserver(subject);
    new OctalObserver(subject);
    new BinaryObserver(subject);

    cout << "First state change: 15" << endl;
    subject->setState(15);
    cout << "Second state change: 10" << endl;
    subject->setState(10);
    */
